package com.repair.project.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.repair.project.config.R;
import com.repair.project.entity.Cycle;
import com.repair.project.entity.Student;
import com.repair.project.service.CycleService;
import com.repair.project.service.StudentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hz
 * @since 2021-01-12
 */
@RestController
@RequestMapping("/project/cycle")
public class CycleController {



    @Autowired
    CycleService cycleService;

    @ApiOperation("接口描述：获取轮播图")
    @GetMapping("getCycleList")
    public R getCycleList(@RequestParam(value = "page")int page, @RequestParam(value = "limit")int limit,
                        @RequestParam(required = false, value = "status")String statu){

        List<Cycle> cycle =cycleService.list(null);

        Page<Cycle> cyclePage = new Page<>(page, limit);

        QueryWrapper<Cycle> objectQueryWrapper = new QueryWrapper<>();
        if(statu!=null) {
            objectQueryWrapper.eq("statu", statu);
        }
        IPage<Cycle> cycleIPage = cycleService.page(cyclePage, objectQueryWrapper);
        return R.ok().data("datalist",cycleIPage);
    }

    @ApiOperation("接口描述:增加轮播图")
    @PostMapping("addCycle")
    public R addCycle(@RequestBody Cycle cycle){
        return R.ok().data("data",cycleService.save(cycle));
    }

    @ApiOperation("接口描述：删除轮播图")
    @GetMapping("delCycle")
    public R delCycle(@RequestParam(value = "cycleid")int cycleid){
        return R.ok().data("data",cycleService.removeById(cycleid));
    }

    @ApiOperation("接口描述：更新轮播图")
    @PostMapping("updCycle")
    public R updCycle(@RequestBody Cycle cycle){
        return R.ok().data("data",cycleService.updateById(cycle));
    }






}

